package com.yq.core.util;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yq.core.constant.Constant;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.util.Iterator;
import java.util.List;
import java.util.Map;


/**
 * 信  息: [yinquan] [2017-03-04] [1.2];
 * 描  述: 信息状态返回类，同意使用此类返回数据
 */

public class Result {

    private static Logger logger = LoggerFactory.getLogger(Result.class);
    
    // 返回代码, 查看Constant
    private String code;
    // 返回状态
    private int state;
    // 返回提示信息
    private String msg;
    // 返回数据
    private Object data;
    // 是否通过校验
    private boolean pass;
    // token
    private String token;

	/*********************************************************************************/

	/**
	 * 返回成功
	 * @param msg msg=null使用默认提示信息
	 * @param data 需要传递的数据
     */
	public void resoutSucess(String msg, Object data) {
		this.code = Constant.CODE_100;
		this.state = Constant.STATE_SUCESS;
		this.msg = msg==null?Constant.MSG_SUCESS_DEFAULT:msg;
		this.data = data;
	}
	/**
	 * 返回失败
	 * @param msg msg=null使用默认提示信息
	 */
	public void resoutError(String msg) {
		this.code = Constant.CODE_101;
		this.state = Constant.STATE_ERROR;
		this.msg = msg==null?Constant.MSG_ERROR_DEFAULT:msg;
	}
	/**
	 * 返回失败
	 * @param code 错误代码
	 * @param msg msg=null使用默认提示信息
	 */
	public void resoutError(String code, String msg) {
		this.code = code;
		this.state = Constant.STATE_ERROR;
		this.msg = msg==null?Constant.MSG_ERROR_DEFAULT:msg;
	}

	public String unExist(String target) {
		return target + Constant.MSG_ERROR_UNEXIST;
	}

	/*********************************************************************************/

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public boolean isPass() {
		return pass;
	}

	public void setPass(boolean pass) {
		this.pass = pass;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

}
